//
//  APEdgesLabel.swift
//  APSwift
//
//  Created by AbnerPei on 2021/12/30.
//

import UIKit

class APEdgesLabel: UILabel {
    
    /// 控制内边距
    public var edgeInsets: UIEdgeInsets = UIEdgeInsets(top: 0, left: 2, bottom: 0, right: 2)
    
    override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect {
        var rect = super.textRect(forBounds: bounds.inset(by: edgeInsets), limitedToNumberOfLines: numberOfLines)
        rect.origin.x -= edgeInsets.left
        rect.origin.y -= edgeInsets.top
        rect.size.width += (edgeInsets.left + edgeInsets.right)
        rect.size.height += (edgeInsets.top + edgeInsets.bottom)
        return rect
    }
    
    override func drawText(in rect: CGRect) {
        super.drawText(in: rect.inset(by: edgeInsets))
    }
}
